/***************************************************************************
 *   Copyright (C) 2007 by Warren Kenny   *
 *   warren.kenny@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef OTAIPHEADER_H
#define OTAIPHEADER_H

#define OTA_IP_HEADER_LENGTH 20
#define OTA_IP_PROTOCOL_TCP 0x06

/**
	@author Warren Kenny <warren.kenny@gmail.com>
*/

#include <otaCore.h>

class otaIPHeader
{
public:
	otaIPHeader();

	otaIPHeader( unsigned char version, 
		     unsigned char typeOfService, 
		     unsigned short totalLength,
		     unsigned short identification,
		     unsigned short fragmentationOffset,
		     unsigned char timeToLive,
		     unsigned char protocol,
		     unsigned short checksum,
		     unsigned long sourceIP,
		     unsigned long destinationIP );
	
    	bool deserialize( const char *data, const unsigned int dataSize, const unsigned int offset, unsigned int &newOffset );
    
    	bool serialize( char *data, const unsigned int dataSize, const unsigned int offset, unsigned int &newOffset );
	
	unsigned long getSourceIP();
	
	unsigned long getDestinationIP();
	
	unsigned char getProtocol();
    
	unsigned char getHeaderLength();
	
    	~otaIPHeader();

private:
	
	unsigned char 		m_version;
	unsigned char 		m_typeOfService;
	
	unsigned short 		m_totalLength;
	unsigned short 		m_identification;
	unsigned short 		m_fragmentationOffset;
	
	unsigned char 		m_timeToLive;
	unsigned char 		m_protocol;
	
	unsigned short 		m_checksum;
	
	unsigned long 		m_sourceIP;
	unsigned long		m_destinationIP;
};

#endif
